package com.xge.business

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.utils.TextUtils
import com.xge.business.databinding.ActivityQueryBinding
import com.xge.business.utils.ConstellationUtils
import com.xge.business.utils.DateDiffUtils
import com.xge.business.utils.ZodiacUtils

class QueryActivity: AppCompatActivity() {

    private lateinit var binding:ActivityQueryBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityQueryBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.tvSxQuery.setOnClickListener {
            //生肖查询

            val date = binding.edOutYear.text.toString()
            if(TextUtils.isEmpty(date)){
                return@setOnClickListener
            }
            val result = ZodiacUtils.getZodiac(date)
            if(result == "111"){
                Toast.makeText(this,"输入年份错误",Toast.LENGTH_SHORT).show()
            }else{
                binding.tvSx.text = result
            }
        }

        binding.tvXzQuery.setOnClickListener {
            //生肖星座
            val date = binding.edOutTime.text.toString()
            if(TextUtils.isEmpty(date)){
                return@setOnClickListener
            }
            val result = ConstellationUtils.getConstellation(date)
            if(result == "000"){
                Toast.makeText(this,"请输入正确的日期格式：mm-dd",Toast.LENGTH_SHORT).show()
            }else if(result == "111"){
                Toast.makeText(this,"您输入的日期不合法",Toast.LENGTH_SHORT).show()
            }else{
                binding.tvXz.text = result
            }
        }

        binding.tvRqQuery.setOnClickListener {
            //天数
            val date = binding.tvDate.text.toString()
            if(TextUtils.isEmpty(date)){
                return@setOnClickListener
            }
            val result = DateDiffUtils.getDaysFromToday(date)
            if(result != null){
                binding.tvNumber.text = result.days.toString()
                if(result.type == "past"){
                    binding.tvType.text = "已过去"
                }else if(result.type == "future"){
                    binding.tvType.text = "还剩"
                }
            }else{
                Toast.makeText(this,"请输入正确的日期格式：yyyy-mm-dd",Toast.LENGTH_SHORT).show()
            }
        }
    }
}